package com.nageoffer.shortlink.admin.remote.dto;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.shortlink.admin.common.convention.result.Result;
import com.nageoffer.shortlink.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.nageoffer.shortlink.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.nageoffer.shortlink.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.nageoffer.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;


/**
 * @Author: 刘新智
 * @Date: 2025/10/23 11:11
 * @Description: 短链接后管远程调用接口层
 * @Version: v1.0
 */


public interface ShortLinkRemoteService {
    String SHORT_LINK_PROJECT_PAGE_URL = "http://127.0.0.1:8001/api/shortlink/v1/link/page";
    String SHORT_LINK_PROJECT_CREATE_URL = "http://127.0.0.1:8001/api/shortlink/v1/link/create";

    /**
     * @description: 短链接分页查询
     * @author: 刘新智
     * @date: 2025/10/23 13:48
     * @param: [requestParam]
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<com.baomidou.mybatisplus.core.metadata.IPage<com.nageoffer.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO>>
     **/
    default Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO requestParam) {

        // 发送请求
        String resultStr = HttpUtil.post(SHORT_LINK_PROJECT_PAGE_URL, JSON.toJSONString(requestParam));

        // 使用 FastJSON 解析
        return JSON.parseObject(resultStr, new TypeReference<Result<IPage<ShortLinkPageRespDTO>>>() {});
    }


    /**
     * @description: 创建短链接
     * @author: 刘新智
     * @date: 2025/10/23 13:48
     * @param: [requestParam]
     * @return: com.nageoffer.shortlink.admin.common.convention.result.Result<com.nageoffer.shortlink.admin.remote.dto.resp.ShortLinkCreateRespDTO>
     **/
    default Result<ShortLinkCreateRespDTO> createShortLink(ShortLinkCreateReqDTO requestParam) {

        // 发送请求
        String resultStr = HttpUtil.post(SHORT_LINK_PROJECT_CREATE_URL, JSON.toJSONString(requestParam));

        // 使用 FastJSON 解析
        return JSON.parseObject(resultStr, new TypeReference<Result<ShortLinkCreateRespDTO>>() {});
    }

}